#! /bin/bash
##############################################################
##
## Name		:	m_sakila_meta_data
## Author	:	Bradley Atkins
## Description	:	
## Date		:	16/09/2012
## Args		:	
## Status	:	Reviewed 	[n]
##			Tested 		[n]
##			Released 	[n]
##
## M_JOB_HOST
## M_GREP_PATTERN "error|info|warning"
##
##############################################################
SCRIPT_NAME=m_sakila_meta_data

TMPFILE="$(m_get_tmp_file ${SCRIPT_NAME})" || 
	m_fail 1 "Error:Failed to get tmp file (${SCRIPT_NAME})" 
ACTFILE="$(m_get_exp_file ${SCRIPT_NAME})" || 
	m_fail 1 "Error:Failed to get exp file (${SCRIPT_NAME})" 

#======================================
# Read our table and column names
#======================================
mysql -u${SK_USER} -p${SK_PASSWD} -h${SK_HOST} ${SK_NAME} -t <<EOF > ${TMPFILE} || m_fail 1 "Error: (${SCRIPT_NAME})" 

	SELECT table_name, column_name FROM INFORMATION_SCHEMA.columns \G

EOF

#======================================
# Compare our table and column names
#======================================
awk '($0 !~ /^[*]/){print $2}' FS=": " ${TMPFILE} | 
	awk '(NR%2 == 0){print;next}{printf "%s", $0":"}' | 
		sort --key=1,2 > ${ACTFILE}

EXPFILE=$(m_find_file ${SCRIPT_NAME}.exp) || 
	m_fail 1 "Error:Failed to find exp file (${SCRIPT_NAME})" 

diff ${ACTFILE} ${EXPFILE} > ${TMPFILE} 

if [[ -s ${TMPFILE} ]]
then
	m_print_marker ${C_EVIDENCE_MARKER}
	cat ${TMPFILE} || m_fail 1 "Error:Cat failed (${SCRIPT_NAME})" 
	m_print_marker ${C_EVIDENCE_MARKER}
fi

